package com.bjpowernode.p2padmin.user.controller;

import com.bjpowernode.p2padmin.user.model.UserInfo;
import com.bjpowernode.p2padmin.user.service.UserService;
import org.apache.catalina.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

/**
 * ClassName:UserController
 * Package:com.bjpowernode.p2padmin.user.controller
 * Description:TODO描述
 *
 * @date:2020/4/6 11:27
 * @author:CC
 */

@Controller
public class UserController {

    @Resource
    private UserService userService;

    @RequestMapping("/")
    public String toLogin(){

        return "login";
    }

    @RequestMapping("/login")
    public String login(String username, String password, HttpSession session, Model model){

        UserInfo user =userService.login(username,password);

        if (user==null){
            model.addAttribute("errorMessage","账号或密码有误");
            return "login";
        }

        session.setAttribute("userSession",user);

        return "redirect:/main";
    }

    @RequestMapping("/noLogin")
    public String noLogin(){
        return "login";
    }
    @RequestMapping("/noPermission")
    public String noPermission(){
        return "myError";
    }


    @RequestMapping("/main")
    public String main(){

        return "main";
    }




}
